package cn.jiyun.controller;import cn.jiyun.common.config.Result;
import cn.jiyun.entity.XmAdvertisements;
import cn.jiyun.service.IXmAdvertisementsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-27
 */
@RestController
@RequestMapping("/xm-platform/xm-advertisements")
public class XmAdvertisementsController {
    @Autowired
    private IXmAdvertisementsService xmAdvertisementsService;
    @RequestMapping("/findPage")
    public Result findPage(Integer pageNum, Integer pageSize, @RequestBody XmAdvertisements xmAdvertisements){
        Page page = xmAdvertisementsService.findPage(pageNum,pageSize,xmAdvertisements);
        return Result.ok(page);
    }
    @RequestMapping("/findById")
    public Result findById(Integer id){
        XmAdvertisements advertisements = xmAdvertisementsService.getById(id);
        return Result.ok(advertisements);
    }
    @RequestMapping("/add")
    public Result add(@RequestBody XmAdvertisements advertisements){
        if (advertisements.getId()==null){
            advertisements.setEffectiveDateStart(LocalDateTime.now());
            advertisements.setCreationDate(LocalDateTime.now());
            advertisements.setStime(LocalDateTime.now());
            advertisements.setStatus("1");
            xmAdvertisementsService.save(advertisements);
            return Result.ok("添加成功！");
        }else {
            advertisements.setEffectiveDateStart(LocalDateTime.now());
            xmAdvertisementsService.updateById(advertisements);
            return Result.ok("修改成功！");
        }
    }
    @RequestMapping("/zhuangtai")
    public Result zhuangtai(Integer id,String status){
        XmAdvertisements notification = new XmAdvertisements();
        notification.setId(id);
        notification.setStatus(status);
        xmAdvertisementsService.updateById(notification);
        return Result.ok("已读");
    }

}
